import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import scoreatpercentile
from scipy import stats
import scipy as sp

def orignial(x):
    return -0.58016 + x * 15.03525

def extended(x):
    return 1.88602 + x *  15.10937

def robust(x):
    return -1.8759 + x * 15.4742

def lad(x):
    return 1.04441 + x * 15.27522


#--------------------------------------------------------------------------
#MAIN

if __name__ == "__main__":
    data = [[20, 2], [60, 4], [46, 3], [41, 2], [12, 1], [137, 10], [68, 5], [89, 5], [ 4, 1], [32, 2], [144, 9],
    [156, 10], [93, 6], [36, 3], [72, 4], [100, 8], [105, 7], [131, 8], [127, 10], [57, 4], [66, 5], [101, 7],
    [109, 7], [74, 5], [134, 9], [112, 7], [18, 2], [73, 5], [111, 7], [96, 6], [123, 8], [90, 5], [20, 2],
    [28, 2], [3, 1], [57, 4], [86, 5], [132, 9], [112, 7], [27, 1], [131, 9], [34, 2], [27, 2], [61, 4], [77, 5]]
    
    data = np.array(data)

    extraData = np.array([[132, 6], [166, 5]])

    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    #print data[:,0]
    ax.scatter(data[:,1], data[:,0], marker = 'x')
    ax.scatter(extraData[:,1], extraData[:,0])
    ax.set_xlabel('The number of copiers')
    ax.set_ylabel('Total number of minutes')
    ax.set_xlim([0, 11])
    ax.set_ylim([-10, 170])

    #ax.plot([0, 12], [orignial(0), orignial(12)], '--', label = 'original')
    #ax.plot([0, 12], [extended(0), extended(12)], label = 'extended')
    
    ax.plot([0, 12], [extended(0), extended(12)], '--', label = 'OLS')
    #ax.plot([0, 12], [robust(0), robust(12)], label = 'IRLS')
    ax.plot([0, 12], [lad(0), lad(12)], label = 'LAD')
    leg = ax.legend(('OLS', 'LAD'), 'lower right', shadow=True)
    #plt.figlegend((line1, line2), ('label1', 'label2'),'upper right' )
    #plt.figlegend('upper right' )
    #frame  = leg.get_frame()  
    #frame.set_facecolor('0.80')

    plt.show()
    